package Core::ListIterator;
use strict;
use warnings;
use vars qw{ @ISA @EXPORT $END };
use Exporter;


@ISA = qw( Exporter );
@EXPORT = qw (
   ListIterator
);

$END = "'__END__'";

sub ListIterator
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RETURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	my ( $rcFunc ) = shift;
	return Core::ListIterator->new( $rcFunc );
}

sub new
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RETURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	my( $rhClass ) = shift;               # Object    
    my( $rhSelf ) = {};
    bless( $rhSelf, $rhClass);
    
	my( $rcFunc )    =   shift; 
	return 0 if not $rcFunc or 
				ref( $rcFunc ) !~ /^CODE/;
	$rhSelf->{ FUNC } = $rcFunc;
    return $rhSelf;	
}

sub hasNext
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RETURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	my ( $rhSelf ) = shift; 
	return 0 if not $rhSelf->{ FUNC };
	my $sValue = $rhSelf->{ FUNC }->();
	if( $sValue ne $END ){
		$rhSelf->{ NEXT } = $sValue;
	}
	else{
		$rhSelf->{ END }++;
		delete $rhSelf->{ NEXT };
	}
	
	$rhSelf->{ END } ? 0 : 1; 
}	


sub next
#*****************************************************************************
# PURPOSE:
# USAGE: 
# PASSED ARGS:
# RETURN ARGS:
# $sError - Fail Error Message
#*****************************************************************************
{
	my ( $rhSelf ) = shift; 
	return $rhSelf->{ NEXT };
}	


1
__END__;